package com.controller;

import com.entity.ContestCreditsEntity;
import com.entity.vo.ContestCreditsVo;
import com.service.impl.ContestCreditsServiceImpl;
import com.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author mgl
 * @version 1.0
 * @description 竞赛加分控制器
 * @date 2024/4/10 13:54
 */
@RestController
@RequestMapping("/credits")
public class ContestCreditsController {

    @Autowired
    private ContestCreditsServiceImpl creditsService;

    @ApiOperation("增加一条加分记录 需要传的参数参考model中的ContestCreditsEntity")
    @PostMapping("/add")
    public R addCredits(@RequestBody ContestCreditsEntity contestCredits) {
        creditsService.insert(contestCredits);
        return R.ok();
    }

    @ApiOperation("修改加分记录 需要传的参数参考model中的ContestCreditsEntity")
    @PostMapping("/update")
    public R updateById(@RequestBody ContestCreditsEntity contestCredits) {
        creditsService.updateById(contestCredits);
        return R.ok();
    }

    @ApiOperation("查询列表 返回一个列表 字段参考model中的ContestCreditsVo")
    @ApiResponse(code = 200, message = "成功情况下返回的是一个数组", response = ContestCreditsVo.class)
    @GetMapping("/selectList")
    public R selectList(@RequestParam("page") Integer pageNo,
                        @RequestParam("limit")Integer pageSize,
                        @RequestParam(value = "contestTypeName", required = false)String contestTypeName) {
        if (contestTypeName == null) contestTypeName = "%%";
        int length = creditsService.selectAll(null, null, contestTypeName).size();
        return R.ok().put("data", creditsService.selectAll(pageNo, pageSize, contestTypeName))
                .put("length", length);
    }

    @ApiOperation("删除")
    @GetMapping("/delete")
    public R deleteById(@RequestParam("ids") @ApiParam List<Integer> ids) {
        creditsService.deleteBatchIds(ids);
        return R.ok();
    }

    @ApiOperation("无用接口  为了展示一个实体类ContestCreditsVo的字段信息")
    @GetMapping("/test1")
    public R test1(@RequestBody ContestCreditsVo contestCreditsVo) {
        return R.ok();
    }


}
